package com.stx.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.stx.dao.CuDao;
import com.stx.domain.Absent;
import com.stx.domain.Student;
@Repository
public class CuDaoImpl implements CuDao {
	@Resource
	private JdbcTemplate jt;
	
	public int addAbsent(Absent absent,Student student){	
		Date date=new Date();
		  DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		  String time=format.format(date);
		String sql="insert into  cu   values(id.nextval,?,?,?,?,?,?,?)";
		Object[] obj = {time, absent.getNo(),student.getName(),student.getMajor(),absent.getThing(),student.getD() ,absent.getT()};
		return jt.update(sql, obj);
	}
	
	public void absentDelete(int id){	
		jt.update("delete from cu where id='"+id+"'");
	}
	
	public List<Absent> selectAbsentUploading() {
		String sql="select * from cu ";
		List<Absent> list = jt.query(sql, new info());
		System.out.println("di"+list.size());
		return list;
		
		
		
	}
	
	class info implements RowMapper {
	@Override
	public Object mapRow(ResultSet rs, int arg1) throws SQLException {		
		Absent absent=new Absent();
		absent.setId(rs.getInt("id"));
		absent.setNo(rs.getInt("no"));
		absent.setName(rs.getString("name"));
		absent.setMajor(rs.getString("major"));
		absent.setD(rs.getString("d"));
		absent.setTime(rs.getString("time"));
		absent.setThing(rs.getString("thing"));
		absent.setT(rs.getString("t"));
		return absent;
	}
}


}
